const redis=require('../models/redis.server.model');
const map={
    reg:'注册用户',
    post:'发表话题',
    comment:'发表评论',
    editComment:'编辑评论',
    setting:'设置',
    createApp:'创建应用',
    settingApp:'管理应用'
};

module.exports=opts=>async (ctx,next)=>{
    let ret=await redis.getLimit({action:opts.action,id:ctx.session.loginUser._id});
    if(ret){
        ctx.flash={notify:`[${map[opts.action]}]频繁，请稍候再试`};
        return await ctx.redirect('/notify');
    }
    await next();
};